package com.zkingsoft.service.impl;

import com.zkingsoft.service.BizShopService;
import com.matrix.core.constance.SystemErrorCode;
import com.zkingsoft.bean.BizShop;
import com.zkingsoft.common.bean.SysUsers;
import com.zkingsoft.dao.BizShopDao;

import org.springframework.stereotype.Service;

import java.util.Map;

import com.matrix.core.constance.MatrixConstance;
import com.matrix.core.exception.GlobleException;
import com.matrix.core.pojo.PaginationVO;
import com.matrix.core.tools.ModelUtils;

import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

import com.matrix.core.tools.WebUtil;
import com.matrix.core.tools.UUIDUtil;

/**
 * @description service接口实现类(门店信息表)
 * @author 肖崇高
 * @date 2018-05-23 20:39
 */
@Service
public class  BizShopServiceImpl implements  BizShopService{

	
	@Autowired
	private BizShopDao bizShopDao;
	
	
	@Override
	public int add(BizShop bizShop){
		// 设置基本字段信息
 
		bizShop.setId(UUIDUtil.getRandomID());
		return bizShopDao.insert(bizShop);
		
	}
	
	@Override
	public int batchAdd(List<BizShop>  bizShopList) {
		//这里没有做基本字段的设置，如有需要请自己实现	
		int num = 0;
		int c = 10000;
		int size = bizShopList.size()/c + 1;
		for(int i=0; i<size; i++) {
			int begin = i*c;
			int end = (i+1)*c;
			end = end >= bizShopList.size() ? bizShopList.size() : end;
			List<BizShop> insertList = bizShopList.subList(begin, end);
			num += bizShopDao.batchInsert(insertList);
		}
		return num;
		
	}
	
	
   	
    @Override
	public int modifyByMap(BizShop oldBizShop
	,BizShop newBizShop){
	
		Map<String, Object> modifyMap = null;
		try {
			if (!ModelUtils.isModified(oldBizShop, newBizShop)) {
				return MatrixConstance.DML_SUCCESSS;
			}
			modifyMap = ModelUtils.comparePojo2Map(oldBizShop, newBizShop);
		} catch (Exception e) {
			throw new GlobleException(SystemErrorCode.DATA_UPDATE_FAIL, e, newBizShop);
		}
		if (modifyMap.size() > 0) {
			modifyMap.put("id", oldBizShop.getId());
			bizShopDao.updateByMap(modifyMap);
		}
		return MatrixConstance.DML_SUCCESSS;
	}
	
	@Override
	public int modifyByModel(BizShop bizShop){
	
		return bizShopDao.updateByModel(bizShop);
	
	}
	
	
	
	@Override
	public int remove(List<String> list){
	
		return bizShopDao.deleteByIds(list);
	
	}

	@Override
	public int removeById(String id){
	
		return bizShopDao.deleteById(id);
	
	}
	
	@Override
	public int removeByModel(BizShop bizShop){
	
		return bizShopDao.deleteByModel(bizShop);
	
	}
	
	
	@Override
	public List<BizShop> findInPage(BizShop bizShop,  PaginationVO pageVo){
	
		return bizShopDao.selectInPage(bizShop , pageVo);
	
	}
	
	@Override
	public List<BizShop> findByModel(BizShop bizShop){
	
		return bizShopDao.selectByModel(bizShop);
	
	}
	
	@Override
	public int  findTotal(BizShop bizShop){
	
		return bizShopDao.selectTotalRecord(bizShop);
	
	}
	
	@Override
	public BizShop  findById(String id){
	
		return bizShopDao.selectById(id);
	
	}

}